package com.example.demo.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 库存实体
 */
@Data
@Entity
@Table(name = "inventory")
@EqualsAndHashCode(callSuper = true)
public class Inventory extends BaseEntity {
    
    @Column(name = "product_id", nullable = false)
    private Long productId;
    
    @Column(name = "warehouse_id", nullable = false)
    private Long warehouseId;
    
    @Column(name = "current_stock", nullable = false)
    private Integer currentStock = 0;
    
    @Column(name = "reserved_stock", nullable = false)
    private Integer reservedStock = 0;
    
    @Column(name = "available_stock", nullable = false)
    private Integer availableStock = 0;
    
    @Column(name = "min_stock_level")
    private Integer minStockLevel = 0;
    
    @Column(name = "max_stock_level")
    private Integer maxStockLevel;
    
    @Column(name = "cost_price", precision = 10, scale = 2)
    private BigDecimal costPrice;
    
    @Column(name = "last_inbound_time")
    private LocalDateTime lastInboundTime;
    
    @Column(name = "last_outbound_time")
    private LocalDateTime lastOutboundTime;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false)
    private InventoryStatus status = InventoryStatus.NORMAL;
    
    /**
     * 库存状态枚举
     */
    public enum InventoryStatus {
        NORMAL("正常"),
        LOW_STOCK("库存不足"),
        OUT_OF_STOCK("缺货"),
        OVERSTOCK("库存过多");
        
        private final String description;
        
        InventoryStatus(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
}
